package com.xiaoxiao.springbootstudy.mapper;

import com.xiaoxiao.springbootstudy.pojo.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xiaoxiao.springbootstudy.pojo.vo.CountResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author XiaoXiao
 * @description 针对表【t_user】的数据库操作Mapper
 * @createDate 2025-05-19 14:34:27
 * @Entity com.xiaoxiao.springbootstudy.pojo.User
 */
public interface UserMapper extends BaseMapper<User> {
    @Insert("insert into t_user values(null, #{uname}, #{upwd}, #{phone}, #{edu}, #{age}, #{title})")
    void saveUserMapper(User user);

    @Select("""
            select count(id) 'value',
                            CASE
                                WHEN age between   18 and  25 THEN '[18 - 25]'
                                WHEN age between   26 and  30 THEN '[26 - 30]'
                                WHEN age between   31 and  35 THEN '[31 - 35]'
                                WHEN age between   36 and  40 THEN '[36 - 40]'
                                WHEN age between   41 and  45 THEN '[41 - 45]'
                                ELSE
                                    '[56 - 100]'
                                END 'name'
                    from t_user
                    group by name
            """)
    public List<CountResult> countEmployeeAgeMapper();

    @Select("select edu name,count(id) value from t_user group by edu")
    public List<CountResult> countEmployeeEduMapper();
}




